﻿using Adnc.Application.Shared;
using Adnc.Application.Shared.Dtos;
using Adnc.WebApi.Shared;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using WYT.Usr.Application.Contracts.Dtos.Warehouse;
using WYT.Usr.Application.Contracts.Services;

namespace WYT.Usr.WebApi.Controllers
{
    /// <summary>
    /// 用户云仓服务
    /// </summary>
    [Route("usr/[Controller]")]
    [ApiController]
    public class WarehouseController : AdncControllerBase
    {
        private readonly IWarehouseAppService _warehouseAppService;
        private readonly IUserContext _userContext;

        public WarehouseController(IWarehouseAppService warehouseAppService
            , IUserContext userContext)
        {
            _warehouseAppService = warehouseAppService;
            _userContext = userContext;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("test")]
        [AllowAnonymous]
        public async Task<ActionResult<bool>> Test([FromQuery]long id)
        {
            return Result(await _warehouseAppService.InventoryManagement(id));
        }

        /// <summary>
        /// 获取云仓出库记录列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("loglist")]
        public async Task<WYTActionResult<PageModelDto<WarehouseLogDto>>> GetUserWarehouseLogList([FromQuery] WarehouseLogSearchDto input)
        {
            return Success(await _warehouseAppService.GetUserWarehouseLogList(_userContext.Id, input));
        }

        /// <summary>
        /// 获取用户云仓商品总的数量
        /// </summary>
        /// <returns></returns>
        [HttpGet("total")]
        public async Task<WYTActionResult<int>> GetUserWarehouseCount()
        {
            return Success(await _warehouseAppService.GetUserWarehouseCount(_userContext.Id));
        }

        /// <summary>
        /// 获取用户云仓商品列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<WYTActionResult<List<WarehouseDto>>> GetUserWarehouse([FromQuery] SearchDto input)
        {
            return Success(await _warehouseAppService.GetUserWarehouse(_userContext.Id, input));    
        }
        /// <summary>
        /// 云仓自提列表
        /// </summary>
        /// <param name="Language"></param>
        /// <returns></returns>
        [HttpGet("list2")]
        public async Task<WYTActionResult<List<WarehouseClassificationDto>>> ClassificationGetUserWarehouse([FromQuery] string Language = "ZH")
        {
            return Success(await _warehouseAppService.ClassificationGetUserWarehouse(_userContext.Id, Language));
        }

        #region 内部接口
        /// <summary>
        /// 获取用户云仓商品列表
        /// </summary>
        /// <param name="Ids">商品规格ID</param>
        /// <returns></returns>
        [HttpGet("_list")]
        public async Task<ActionResult<List<WarehouseSimpleDto>>> GetRPCUserWarehouse()
        {
            return Result(await _warehouseAppService.GetWarehouseSimplesAsync(_userContext.Id));
        }
        #endregion
    }
}
